<template>
	<view class="page_box" :class="{'ov':isframe}" v-if="!loading" :style="{'background': setData.bgcolor,'padding-bottom':setData.vote_reg?'170rpx':'10rpx'}">
		<view class="ac_header" :style="{'background': 'url('+setData.banner+') center center no-repeat'}">
			<view class="section_top" v-if="setData.bulletin!=''">
				<uni-notice-bar background-color="rgba(0,0,0,0.5)" show-icon color="#fff" icon="info-filled" :speed="50" scrollable :text="setData.bulletin" />
			</view>
			<view class="info_control">
				<div class="music" :style="{'background':openMusic?'rgba(0,0,0,.5)':'none'}">
					<MusicAutoPlay class="open" ref="audioCon" :music="setData.bgmusic" v-if="openMusic"></MusicAutoPlay>
				</div>
				<div class="complain" @click="next(5)">投诉</div>
			</view>
			<div class="btn_icon">
				<div class="icon_box" @click="next(0)" v-if="activityText.open_gift">
					<img src="~@/static/vote/gift.png" alt="">
				</div>
				<div class="icon_box" @click="next(1)"  v-if="setData.prize_open">
					<img src="~@/static/vote/prize.png" alt="">
				</div>
				<div class="icon_box" @click="next(2)">
					<img src="~@/static/vote/share.png" alt="">
				</div>
				<div class="icon_box" v-if="setData.open_ranking" @click="next(3)">
					<img src="~@/static/vote/sort.png" alt="">
				</div>
				<div class="icon_box" @click="next(4)" v-if="data.activity_rules!=''">
					<img src="~@/static/vote/rules.png" alt="">
				</div>
			</div>
		</view>
		<view  class="ac_content" :style="{'padding-bottom':setData.vote_countdown || setData.vote_reg || setData.show_data?'40rpx':'80rpx'}">
			<view class="timer_con" v-if="(setData.vote_countdown || setData.vote_reg || setData.show_data) && setData.vote_open_reg">
				<div class="timer" v-if="setData.vote_countdown">
					<template v-if="showTimerStatus">
						 {{activityStatusText}}：<span>{{timeStampText.d}}</span>天<span>{{timeStampText.h}}</span>:<span>{{timeStampText.m}}</span>:<span>{{timeStampText.s}}</span>
					</template>
					<template v-else>
						{{activityStatusText}}
					</template>
				</div>
				<div ref="action" ></div>
				<div class="action" v-if="setData.vote_reg">
					<div class="t_btn" @click="next(6)" v-if="checkShow" :style="{background:setData.second_color,color: setData.second_text_color}">{{setData.vote_reg_button ||''}}</div>
					<div class="t_btn g" :class="{'one':!checkShow}" @click="next(7)" :style="{background:setData.button_color,color: setData.button_font_color}">{{setData.vote_works_button ||''}}<img v-if="workStatus.lock_works" src="~@/static/vote/warning@2x.png" alt=""/></div>
				</div>
				<div class="activity_num" :class="{'noworknum':!setData.works_num}" v-if="setData.show_data">
					<div>
						<div>浏览量<div class="under_line" :style="{borderColor:setData.button_color+' transparent transparent transparent'}"></div></div>
						<div>{{activityText.view_num}}</div>
					</div>
					<div class="votes">
						<div>共计{{setData.vote_unit}}数<div class="under_line" :style="{borderColor:setData.button_color+' transparent transparent transparent'}"></div></div>
						<div>{{activityText.play_num}}</div>
					</div>
					<div v-if="setData.works_num">
						<div>作品量<div class="under_line" :style="{borderColor:setData.button_color+' transparent transparent transparent'}"></div></div>
						<div>{{activityText.works_num}}</div>
					</div>
				</div>
			</view>
		<!-- 	<view class="pla">
				
			</view> -->
			<div v-else ref="action" ></div>
			<view class="work">
				<view class="search" v-if="setData.search_bar">
					<input type="text" v-model="WorkKeyWord" placeholder="请输入名称或者编号" confirm-type="search" @confirm="searchWork"/>
					<div class="btn" @click="searchWork" :style="{background:setData.button_color,color: setData.button_font_color}">搜索</div>
				</view>
				<view class="group">
					<ul class="scroll_con">
						<li class="item" v-for="(item,index) in groupData" @click="selectGroup(item,index)">
							{{item.name}} <div v-if="index==selectTab" class="under_line"  :style="{borderColor:setData.button_color+' transparent transparent transparent'}"></div>
						</li>
					</ul>
				</view>
				<view class="work_table">
					<view class="work_card" v-if="setData.work_form_type==2">
						<view class="item" v-for="item in worksData" @click="openWorkDetail(item)">
							<view class="fengmian">
								<view class="number" :style="{background: setData.second_color}">{{item.sortNum}}</view>
								<template v-if="item.attaches.length>0">
									<image :src="checkType(item.attaches[0].url)=='image'?item.cover[0].thumb_url:item.attaches[0].url+'?vframe/jpg/offset/1'" mode="aspectFill"/>
									<img v-if="checkType(item.attaches[0].url)=='video'" class="play" src="~@/static/sports/play.png"/>
								</template>
								<div class="pla_text" v-else>
									<span>{{ item.name }}</span>
								</div>
								<view class="info_con">
									<view class="info">
										<span>{{item.name}}</span>
										<span><span style="color: #FE7F00;"  :style="{color: setData.button_color}">{{setData.vote_quali==1?item.stats.first_num:item.stats.last_num}}</span>{{setData.vote_unit}}</span>
									</view>
									<view class="speak_word" v-if="setData.vote_reg_speak">
										{{item.speak}}
									</view>
								</view>
							</view>
							<view v-if="setData.vote_open_reg" class="btn" @click.stop="votes(item)" :style="{background:setData.button_color,color: setData.button_font_color}">{{setData.vote_button}}</view>
						</view>
					</view>
					<view class="work_list" v-if="setData.work_form_type==1">
						<view class="item" v-for="item in worksData" @click="openWorkDetail(item)">
							<view class="fengmian">
								<view class="number">{{item.sortNum}}</view>
								<template v-if="item.attaches.length>0">
									<image   :src="checkType(item.attaches[0].url)=='image'?item.cover[0].thumb_url:item.attaches[0].url+'?vframe/jpg/offset/1'" mode="aspectFill"/>
									<img v-if="checkType(item.attaches[0].url)=='video'" class="play" src="~@/static/sports/play.png"/>
								</template>
								<div class="pla_text" v-else>
									<span>{{ item.name }}</span>
								</div>
								
							</view>
							<view class="item_content">
								<view class="name">{{item.name}}</view>
								<view class="speak_word"  v-if="setData.vote_reg_speak">
									 {{item.speak}}
								</view>
								<view class="num">
									当前{{setData.vote_unit}}数：<span style="color: #FE7F00;">{{setData.vote_quali==1?item.stats.first_num:item.stats.last_num}}</span>{{setData.vote_unit}}
								</view>
							</view>
							<view class="btn" @click.stop="votes(item)" :style="{background:setData.button_color,color: setData.button_font_color}">{{setData.vote_button}}</view>
						</view>
					</view>
					<template v-if="setData.work_show_type==2">
						<view class="list_more" @click="getMoreWorks" v-if="!workDataIsNoMore ">
							{{sock?'加载中···':'点击加载更多'}}
						</view>
						<view class="noMore" v-if="workDataIsNoMore && setData.work_form_type==1">没有更多了</view>
					</template>
					<template v-if="setData.work_show_type==1">
						<div class="morePla" ref="actionMore"></div>
						<view class="noMoreText" v-if="workDataIsNoMore && setData.work_form_type==1">没有更多了</view>
					</template>
				</view>
				
			</view>	
			<template v-if="(workDataIsNoMore&& setData.work_show_type==1) || setData.work_show_type==2">
				<view style="margin-top: 40rpx;" v-if="setData.service_open">
					<service ></service>
				</view>
				<view style="margin-top: 30rpx;"  v-for="(item,index) in rules" :key="index">
					<view class="info_rule">
						<view>
							<view></view>
							<span>{{item.title}}</span>
							<view></view>
						</view>
						<view>
							 <view class="dec" v-html="item.content">{{item.content}}</view>
						 </view>
					</view>
				</view>
				<div class="sports_swiper" v-if="bottom_ads.length!=0 &&setData.bottom_ad_open==true">
					  <swiper class="swiper" circular :indicator-dots="false" :autoplay="true"  :current="0">
						<swiper-item v-for="(item,index) in bottom_ads" >
						  <div class="swiper_content" @click="jumpNew(item.link)">
							<image  v-if="checkType(item.image)=='image'" class="swiper_img" :mode="'scaleToFill'" :src="item.image"></image>
								<video class="swiper_video" v-if="checkType(item.image)=='video'" :src="item.image" :enable-progress-gesture="false" controls>
								</video>
						  </div>
						</swiper-item>
					  </swiper>
				</div>
				
				<view class="footer_name" v-if="setData.copyright!=''" :style="{padding:setData.vote_countdown || setData.vote_reg || setData.show_data?' 0 0 20rpx':'0'}">
					{{setData.copyright}}
				</view>
			</template>
			<view class="bottom_action fadeInUp" v-if="botm_actions">
				<div class="action"  >
					<div class="t_btn" @click="next(6)" v-if="setData.vote_reg &&checkShow" :style="{background:setData.second_color,color: setData.second_text_color}">{{setData.vote_reg_button ||''}}</div>
					<div class="t_btn g" :class="{'one':!setData.vote_reg && !checkShow}" @click="next(7)" :style="{background:setData.button_color,color: setData.button_font_color}">{{setData.vote_works_button ||''}}<img v-if="workStatus.lock_works" src="~@/static/vote/warning@2x.png" alt=""/></div>
				</div>
			</view>
			<modal v-if="platRule" :showType="8" :data="serviceData"  @close="platRule=false"></modal>
			
			<view class="getMoreTimes" v-if="setData.vote_open_reg">
				<img :src="setData.task_float" @click="openTaskCenter" v-if="taskMenuData.length>0"></img>
			</view>
			
		</view>
		
		<view class="modal_rule fadeIn_an"  @touchmove.prevent v-if="ruleModal">
			
			<view class="content">
				<scroll-view  class="scroll-view"  scroll-y="true" >
					<view class="title">
						活动规则
					</view>
					<view class="_c" v-html="data.activity_rules"></view>
				</scroll-view>
			</view>
			<view class="btn" @click="ruleModal= false">
				<img src="~@/static/guess/close.png" alt=""/>
			</view>
		</view>
		<view class="modal_works"  @touchmove.prevent v-if="modal_works">
			<view class="content">
				<view class="title">
					<span>{{setData.vote_works_button}}</span>
					<img src="@/static/vote/close.png" alt="" @click="modal_works=false">
				</view>
				<view class="list" >
					<scroll-view style="max-height:730rpx;" scroll-y="true" scroll-top="1" v-if="userWorksList.length>0">
						<view class="con_list" v-for="item in userWorksList">
							<view class="item"  @click="openWorkDetail(item)">
								<view class="fengmian" v-if="item.attaches.length>0">
									<image :src="checkType(item.attaches[0].url)=='image'?item.attaches[0].url:item.attaches[0].url+'?vframe/jpg/offset/1'" mode="aspectFill"/>
									<img v-if="checkType(item.attaches[0].url)=='video'" class="play" src="~@/static/sports/play.png"/>
								</view>
								<view class="fengmian"  v-else>
									<div class="pla_text">
										<span>{{ item.name }}</span>
									</div>
								</view>
								<view class="item_content">
									<view class="name">{{item.name}}</view>
									<view class="timer">
										 报名：{{changeTimeStamp((item.created_at))}}
									</view>
									<image v-if="item.status==1" class="stauts_image" src="@/static/vote/allow.png"/>
									<image v-if="item.status==2" class="stauts_image" src="@/static/vote/no_allow.png"/>
									<image v-if="item.status==3" class="stauts_image" src="@/static/vote/warning.png"/>
									<image v-if="item.status==0" class="stauts_image" src="@/static/vote/wait.png"/>
								</view>
								<view class="btn" @click.stop="next(6,item)" v-if="setData.works_edit && item.status!=0">
									 编辑
								</view>
							</view>
							<view class="errmsg" v-if="item.reason!=''" :style="{'errmsg_warning':item.status==0}">{{item.reason}}</view>
							<view class="errmsg" v-if="item.status==3" :style="{'errmsg_warning':true,color:'#D1A131'}">{{toTime(item.lock_expired)}}</view>
						</view>
					</scroll-view>
					<view class="no_more" v-else>
						<view><img src="~@/static/vote/no_works.png" alt=""/></view>
						<span>您还未提交作品</span>
					</view>
				</view>
			</view>
		</view>
		<view class="modal_vote_confirm fadeIn_an"  @touchmove.prevent v-if="voteModal">
			<view class="content">
				<view class="title">
					{{voteData.name}}
				</view>
				<view class="btn">
					<view class="close" @click="voteModal = false">关闭</view>
					<view class="confirm" @click="submitVote">确认</view>
				</view>
				<view class="vote_ads" v-if="lottads.image" @click="jumpNew(lottads.link)">
					<img :src="lottads.image" alt=""/>
				</view>
			</view>
			
		</view>
		<view class="modal_lott fadeIn_an"  @touchmove.prevent v-if="lottModal">
			<view class="content" v-if="lottStatus==0">
				<view class="text">
					{{setData.vote_button}}成功
				</view>
				<view class="vote_ads" v-if="lottads.image" @click="jumpNew(lottads.link)">
					<img :src="lottads.image" alt=""/>
				</view>
				<view class="close" @click="lottModal=false">
					<img src="~@/static/guess/close.png" alt="">
				</view>
			</view>
		</view>
		<votePrize ref="votePrize" title="恭喜你获得一次抽奖机会" :chance="workStatus.lottery" :isNeglect="true" :setData="data" @finish="prizeBack"></votePrize>
		<collectPhone  :data="data" ></collectPhone>
		<advertise  :data="advSet" @close="closeAdv"></advertise>
		<share v-if="showShare" :data="data" @close="showShare=false"></share>
		<guide></guide>
		<help :data="setData" v-if="showHelpModal" @hideMissionModal="hideModal"></help>
		<taskCenter ref="taskcenter" :titleUnit="setData.vote_unit" :show="showTask" :topImage="setData" :list="taskMenuData" @close="handlerCloseTaskCenter" @finish="handlerTaskFinish"></taskCenter>
	</view>
</template>

<script>
	import {getGuess,ActivityInfo,activityText,taskList,getVoteWork,getVoteGroup,getVoteUserWorksList,chance,voteWork} from '@/api/api.js'
	import watermarkOption from '@/until/water.js'
	import {LoginApp,checkLogin,getSystemInfo,isWeiXin,isQianfan,checkPlatform,proxyShareFun,newJumpUrl,tecenctCpta} from '@/until/QFH5.js'
	import { mapGetters } from 'vuex'
	import {formatTime} from '@/until/tool'
	import * as frameJs from '@/model/frameData'
	import help from "../../../components/taskCenter/help";
	import {captID} from '@/model/captTencent.js'
	export default{
		components:{help},
		computed:{
			...mapGetters(['loginInfo','qiniuUrl','guide','updateTask','showCollectPhone']),
			checkShow(){
				if(this.setData.vote_reg && this.activityText.reg_user_num){
					let nowTime = Math.floor(new Date()/1000)
					let {vote_reg,works_limit,vote_user_works_limit,vote_reg_limit} = this.setData
					if(vote_reg.end<nowTime){
						return false
					}
					if( this.activityText.reg_user_num &&vote_reg_limit>0 && this.activityText.reg_user_num>=vote_reg_limit){
						return false
					}
					if(this.workStatus.user_works_num && vote_user_works_limit>0  && this.workStatus.user_works_num >=vote_user_works_limit){
						return false
					}
				}
				return true
			},
		},
		data(){
			return{
				actid:'',
				isframe:false,
				data:'',
				setData:{bgmusic:'',bottom_ad_open:true,copyright:''},
				advSet:'',
				rules:[],
				bottom_ads:[ ],
				gType:'',
				activityText:{has_task:true},
				serviceData:{},
				showStatus:'',
				taskMenuData:[],
				openMusic:true,
				chance:0,
				timeStampText:{
					d:0,
					h:'00',
					m:'00',
					s:'00'
				},
				
				selectTab:0,
				grounpId:'',
				workList:[],
				workListAll:[],
				showTask:false,
				platRule:false,
				pageStatus:-1,//活动状态
				
				worksData:[],
				worksDataAll:[],
				workDataPage:0,
				workDataIsNoMore:false,
				sock:false,
				worksNum:0,
				WorkKeyWord:'',
				groupData:[],
				
				ruleModal:false,
				botm_actions:false,
				showShare:false,
				
				modal_works:false,
				userWorksList:[],
				workStatus:'',
				
				quali:1,
				loading:true,
				
				
				lottModal:false,
				lottads:'',
				lottStatus:0,
				timer:null,
				showTimerStatus:true,
				activityStatusText:'',
				loginStatus:false,
				voteModal:false,
				voteData:null,
				captcha:null,
				captData:null,
				
				showHelpModal: false,
			}
		},
		methods:{
			hideModal() {
			  this.showHelpModal = false
			},
			toTime(time){
				if(time==0)
					return '作品状态异常'
				let timeStr = '作品状态异常，请联系管理员。解封时间：'+formatTime(time)
				return timeStr
			},
			prizeBack(){
				this.initWorksStatus()
			},
			votes(_d){
				let callback = async()=>{
					let nowTime =  Math.floor(new Date()/1000)
					if(nowTime<this.setData.vote_first_date.start){
						uni.showToast({
							title:'活动未开始',
							icon:'none'
						})
						return 
					}
					if(nowTime>this.setData.vote_first_date.end && !this.setData.vote_last){
						uni.showToast({
							title:'活动已结束',
							icon:'none'
						})
						return 
					}
					this.voteData = _d
					//投票前腾讯验证
					let length = this.setData.vote_ads.length
					if(length>0){
						let randomNum = Math.floor(length* Math.random())
						this.lottads = this.setData.vote_ads[randomNum]
					}else{
						this.lottads = {image:''}
					}
					
					let res = await tecenctCpta({works_id:_d.id,actid:this.actid},'vote','vote')
					if(res.data.need_auth){
						this.captcha.show()
						return
					}else{
						this.captData = null
					}
					this.voteModal = true
				}
				this.getAuth(callback)
				
			},
			submitVote(){
				if(!this.loginStatus){
					this.login()
					return
				}
				
				if(this.workStatus.num==0){
					uni.showToast({
						title:'活动次数不足',
						icon:'none'
					})
					if(this.activityText.has_task){
						this.openTaskCenter()
					}
					return
				}
				let obj = {plugin:'vote',actid:this.actid,works_id:this.voteData.id}
				if(this.captData!=null){
					obj.ticket = this.captData.ticket
					obj.rand_str = this.captData.randstr
				}
				voteWork(obj).then(res=>{
					this.voteModal = false
					let _dIndex = this.worksData.findIndex(item=>item.id==this.voteData.id)
					if(res.code==0){
						this.activityText.play_num++
						this.initWorksStatus()
						this.$refs['taskcenter'].getCard()
						let length = this.setData.vote_ads.length
						if(length>0){
							let randomNum = Math.floor(length* Math.random())
							this.lottads = this.setData.vote_ads[randomNum]
						}else{
							this.lottads = {image:''}
						}
						
						if(res.data.lottery==0){
							this.lottStatus = 0
							if(this.setData.vote_quali==1){
								this.worksData[_dIndex].stats.first_num++
							}else{
								this.worksData[_dIndex].stats.last_num++
							}
								this.lottModal = true
						}else{
							this.lottStatus = 1
							if(this.setData.vote_quali==1){
								this.worksData[_dIndex].stats.first_num++
							}else{
								this.worksData[_dIndex].stats.last_num++
							}
								
								
							this.$refs.votePrize.openLott()
						}
					}else{
						uni.showToast({
							title:res.text,
							icon:'none'
						})
					}
				})
			},
			//关闭广告
			closeAdv(){
				this.advSet.start_ad_show = false
				this.advSet.popup_ad_show = false
			},
			//完成任务
			handlerTaskFinish(val){
				if(val && val.type=='share')
					this.showShare = true
				this.initTask()
				this.getChance()
				this.initWorksStatus()
			},
			initWorksStatus(){
				chance({actid:this.actid}).then(res=>{
					this.workStatus = res.data
				}) 
			},
			getChance(){
				this.$refs['taskcenter'].getCard()
			},
			changeTimeStamp(val){
				return formatTime(val,'YYYY-MM-DD')
			},
			jumpNew(url){
			  if('' == url || undefined == url){
			    return;
			  }else{
			    window.open(url)
			  }
			
			},
			checkType(val){
				return this.$checkType(val)
			},
			selectGroup(data,index){
				this.selectTab = index
				this.workDataPage = 0
				this.workDataIsNoMore = false
				if(this.isframe){
					uni.showToast({ icon:'none', title:'模拟数据！' })
					return
				}
				this.grounpId = data.id
				this.initWorks()
			},
			openWorkDetail(val){
				if(this.isframe){
					uni.showToast({ icon:'none', title:'模拟数据！' })
					return
				}
				if(val.status == 0){
					return
				}
				let url = '/plugin/pages/vote/detail?id='+this.actid+'&work_id='+val.id
				this.$navigateTo({ url:url})
			},
			next(val,editData = null){
				if(this.isframe){
					uni.showToast({ icon:'none', title:'模拟数据！' })
					return
				}
				localStorage.setItem(this.actid+'ActivityData',JSON.stringify(this.data))
				//赠礼
				if(val==0){
					let callback=()=>{
						let url ='/plugin/pages/vote/giftList?id='+this.actid
						this.$navigateTo({ url:url})
					}
					this.getAuth(callback,null,true)
				}else if(val==1){//我的奖品
					let callback=()=>{
						
						let url ='/plugin/pages/vote/prize?id='+this.actid
						this.$navigateTo({ url:url})
					}
					this.getAuth(callback,null,true)
				}else if(val==2){//分享好友
					this.showShare= true
				}else if(val==3){//排行榜
					this.$navigateTo({url:'/plugin/pages/vote/sort?plugin='+this.$route.query.plugin+'&type='+this.$route.query.type+"&id="+this.actid})
				}else if(val==4){//活动规则
					 this.ruleModal  = true
				}else if(val==5){//投诉
					let callback=()=>{
						this.$navigateTo({url:'/plugin/pages/complain?id='+this.actid+'&type='+this.type+'&plugin='+this.$route.query.plugin})
					}
					this.getAuth(callback)
				}else if(val==6){//报名
					let now = Math.floor(new Date()/1000)
					if(this.setData.vote_reg_date.end<now && editData==null){
						uni.showToast({
							title:'报名已截止',
							icon:'none'
						})
						return
					}
					if(isQianfan()&&this.setData.vote_reg_platform.indexOf('app')==-1){
						uni.showToast({
							title:'APP当前不支持报名',
							icon:'none'
						})
						return
					}else if( isWeiXin() && this.setData.vote_reg_platform.indexOf('wx')==-1){
						if(this.setData.vote_reg_platform.indexOf('app')>-1){
							this.$store.dispatch('setGuideShow',4)
							return
						}
						uni.showToast({
							title:'H5当前不支持报名',
							icon:'none'
						})
						return
					}
					let callback=()=>{
						let url = '/plugin/pages/vote/join?id='+this.actid
						if(editData!=null){
							url= url + '&isEdit=true&work_id='+editData.id
						}
						this.$navigateTo({url:url})
					}
					this.getAuth(callback)
				}else if(val==7){//我的作品
					this.initUserWork()
				}
			},
			initUserWork(){
				let callback = ()=>{
					getVoteUserWorksList({plugin:'vote',actid:this.actid}).then(res=>{
						this.modal_works = true
						
						this.userWorksList =  res.data || []
					})
				}
				this.getAuth(callback)
			},
			//时间戳倒计时
			startTime(val) {
				clearInterval(this.timer)
				let data = val
				let _this = this
				this.timer = setInterval(() => {
					data--;
					if(data==0){
						clearInterval(this.timer)
					}
					_this.fTime(data)
				}, 1000)
			},
			fTime(time) {
				if(time<=0){
					return
				}
				let day = Math.floor(time / 86400)
				let other = time % 86400
				let hours = Math.floor(other / 3600)
				let minutes = Math.floor(other % 3600 / 60)
				let second = Math.floor(other % 60)
				this.timeStampText={
					d:this.fstr(day),
					h:this.fstr(hours),
					m:this.fstr(minutes),
					s:this.fstr(second)
				}
				
				return day + '天' + this.fstr(hours) + '小时'+ this.fstr(minutes) + '分' +this.fstr(second)+'秒'
			},
			fstr(tr) {
				if (tr > 9) return tr
				return '0' + tr
			},
			async init(){
				if(this.loginStatus){
					this.initWorksStatus()
				}
				
				let res = null
				let nowTime =  Math.floor(new Date()/1000)
				if(!this.isframe){
					res = await ActivityInfo({actid:this.actid})
				}else{
					res = this.frameData
				}
				
				if(res.code == 0){
					// #ifdef H5
					if(res.data.status==0){
						watermarkOption.set('活动未发布')
					}
					// #endif
					
					this.$setTitle(res.data.title)
					uni.setStorageSync('title',res.data.title)
					uni.setStorageSync(this.actid+'ActivityData',JSON.stringify(res.data))
					this.data = res.data
					this.$emit('getData',res.data)
					let {settings} = res.data
					if(settings.vote_quali==1){
						this.startTime(settings.vote_first_date.end-nowTime)
					}else{
						this.startTime(settings.vote_last_date.end-nowTime)
					}
						
					uni.setStorageSync('platform',JSON.stringify(settings.platform))
					this.setData =settings
					this.advSet = settings
					this.openMusic =  settings.bgmusic==''?false:true
					this.bottom_ads = settings.bottom_ads
					//规则排序
					this.rules = []
					let sort = ['prize_intro','business_intro']
					sort.forEach(item=>{
						if(res.data[item]){
							let obj = {title:this.formartText(item),content:res.data[item]}
							this.rules.push(obj)
						}
					})
					this.gType = settings.guess_bg
					this.$store.dispatch('serviceInfo',settings)
				}
				
				
				//处理时间
				let {vote_reg,vote_reg_date,vote_first_date,vote_last,vote_last_date} = res.data.settings
				this.pageStatus = 2
				if(nowTime<res.data.start_time || vote_reg && vote_reg_date.start>nowTime && vote_first_date.start>nowTime){
					this.pageStatus = 0
					this.showTimerStatus = false
					this.activityStatusText = '活动未开始'
				}else if(vote_reg && vote_reg_date.start<nowTime && vote_first_date.start<nowTime && vote_first_date.end>nowTime){
						this.showTimerStatus = true
						this.activityStatusText = '活动进行中'
						this.startTime(vote_first_date.end-nowTime)
				}else if(vote_reg && vote_reg_date.start<nowTime && vote_reg_date.end>nowTime){
						this.showTimerStatus = true
						this.activityStatusText = '报名中'
						this.startTime(vote_reg_date.end-nowTime)
				}else if(vote_reg && vote_reg_date.end>nowTime && vote_first_date.start<nowTime){
						this.showTimerStatus = true
						this.activityStatusText = '活动进行中'
						this.startTime(vote_first_date.end-nowTime)
				}else if(vote_reg && vote_reg_date.end<nowTime && vote_first_date.start>nowTime ){
						this.showTimerStatus = true
						this.activityStatusText = '活动开始倒计时'
						this.startTime(vote_first_date.start -nowTime)
				}else if(vote_reg && vote_first_date.start<nowTime  && vote_first_date.end>nowTime){
						this.showTimerStatus = true
						this.activityStatusText = '活动进行中'
						this.startTime(vote_first_date.end-nowTime)
				}else if(!vote_reg && nowTime<vote_first_date.start){
						this.showTimerStatus = true
						this.activityStatusText = '活动开始倒计时'
						this.startTime(vote_first_date.start - nowTime)
						
				}else if(!vote_reg && nowTime>vote_first_date.start && vote_first_date.end>nowTime){
						this.showTimerStatus = true
						this.activityStatusText = '活动进行中'
						this.startTime(vote_first_date.end-nowTime)
						
				}else if(vote_first_date.end<nowTime &&  !vote_last){
						this.pageStatus = 1
						this.showTimerStatus = false
						this.activityStatusText = '活动已结束'
						
				}else if(vote_first_date.end<nowTime &&  vote_last && vote_last_date.start>nowTime){
						this.showTimerStatus = true
						this.activityStatusText = '二轮准备中'
						this.startTime(vote_last_date.start-nowTime)
				}else if(vote_last_date.end>nowTime &&  vote_last && vote_last_date.start<nowTime){
						this.showTimerStatus = true
						this.activityStatusText = '二轮进行中'
						this.startTime(vote_last_date.end-nowTime)
				}else if(nowTime>res.data.expire_time || nowTime>vote_last_date.end){
					this.pageStatus = 1
					this.showTimerStatus = false
					this.activityStatusText = '活动已结束'
				}
				
				
				if(this.isframe){
					this.loading = false
					return
				}
				
				this.initWorks()
				let data =  res.data
				proxyShareFun(data.settings.title||data.settings.desc,data.settings.image,data.settings.desc,window.location.href)
				
				
				this.loading = false
				this.initBackAction()
				let _this = this
				this.$nextTick(()=>{
					let token = localStorage.getItem(_this.actid+'bearerToken') || null
					if(token!=null && _this.$store.state.long==0 && _this.$store.state.lat==0   && _this.data.area.type==3){
						_this.$store.dispatch('getPos')
						window.getLocationCallBackFun=()=>{}
					}
				})
			},
			login(){
				if(this.checkPlat()){
					LoginApp(this.actid)
				}
			},
			//检查平台
			checkPlat(){
				let plat = checkPlatform()
				if(!plat){
					this.$store.dispatch('setGuideShow',4)
				}
				return plat
			},
			getAuth (callback=()=>{},back=()=>{},isNeglect=false){
				let {isWechat,phone} = this.guide
				if(this.checkPlat()){
					if(!isNeglect && this.pageStatus==0){
						uni.showToast({ title:'活动还没开始呢', icon:'none' })
						return
					}
					if(!isNeglect && this.pageStatus==1){
						uni.showToast({ title:'活动已经结束了', icon:'none' })
						return
					}
					if(!this.loginStatus){
						this.login()
						return
					}
					
					//收集信息
					if(this.data.collect==1 && this.showCollectPhone=='' && isWeiXin()){
						this.$store.commit('SET_SHOWCOLLECT',true)
						return
					}
					if(isQianfan()){
						if(!isWechat){
							this.$store.dispatch('setGuideShow',1)
							back()
							return
						}
						if(phone==""){
							this.$store.dispatch('setGuideShow',2)
							if(this.guaStatus){
								this.resetGua()
								this.guaStatus = false
							}
							return
						}
						callback()
					}else{
						callback()
					}
				}
			},
			openTaskCenter(){
				let callback = ()=>{
					this.showTask = !this.showTask
					this.$refs['taskcenter'].getCard()
				}
				this.getAuth(callback)
			},
			handlerCloseTaskCenter(){
				this.showTask=false
				this.initTask()
		 
			},
			//获取刮奖次数
			 
			formartText(val){
				let {business_intro,activity_rules,prize_intro} = this.setData.custom_desc_key
				switch(val){
					case 'business_intro':return business_intro!=''?business_intro:'商家介绍'
					case 'activity_rules':return activity_rules!=''?activity_rules:'活动规则'
					case 'prize_intro':return prize_intro!=''?prize_intro:'奖品介绍'
				}
			},
			//获取动态文本
			getActivity(){
				activityText({actid:this.actid}).then(res=>{
					if(res.code ==0){
						this.activityText = res.data
						let _this = this
						this.showStatus = true
						if(res.data.has_task && this.taskMenuData.length==0){
							this.initTask()
						}
					}
				})
			},
			initTask(){
				taskList({actid:this.actid}).then(res=>{
					this.taskMenuData = res.data
				})
			},
			initGroup(){
				getVoteGroup({plugin:'vote',actid:this.actid}).then(res=>{
					this.groupData = res.data.group
					let obj = {name:'全部',id:''}
					this.groupData.unshift(obj)
				})
			},
			getMoreWorks(){
				if(this.isframe){
					this.workDataIsNoMore = true
					uni.showToast({ icon:'none', title:'模拟数据！' })
					return
				}
				if(this.sock){
					return
				}
				this.sock = true
				if(this.workDataPage==0){
					this.worksData = this.worksDataAll
					this.sock = false
					if(this.worksDataAll.length<20){
						this.workDataIsNoMore = true
					}
				}
				this.workDataPage++
				if(this.workDataPage>1){
					this.initWorks()
				}
			},
			searchWork(){
				if(this.isframe){
					uni.showToast({ icon:'none', title:'模拟数据！' })
					return
				}
				this.worksData = []
				this.worksDataAll = []
				this.selectTab = 0
				this.workDataPage = 0
				this.workDataIsNoMore = false
				this.sock = true
				this.initWorks()
			},
			initWorks(val=''){
				let obj = { plugin:'vote',actid:this.actid,kw:this.WorkKeyWord,group_id:this.grounpId,page:this.workDataPage==0?1:this.workDataPage }
				getVoteWork(obj).then(res=>{
					let arr = []
					arr = res.data
					arr.map((item,index)=>{
						let length = this.worksData.length
						let sort = item.number
						if(sort<10){
							sort = '00'+sort
						}else if(sort<100){
							sort = '0'+sort
						}
						item.sortNum = sort
					})
					this.worksNum = res._page.totalCount
					if(this.workDataPage<2){
						this.worksData = [...arr.slice(0,6)]
						this.worksDataAll = arr
						if(this.worksDataAll.length<=6){this.workDataIsNoMore=true}
					}else{
						this.worksData = [...this.worksData,...arr]
						if(res.data.length<20){
							this.workDataIsNoMore = true
						}
					}
					this.sock = false
				})
			},
			initBackAction(){
				let _this = this
				
				window.onscroll = function () {
					if(_this.setData.vote_reg ){
						let pixTop = _this.$refs.action.getBoundingClientRect().top +84//84是元素高度
						if(pixTop<=0){
							_this.botm_actions = true
						}else{
							_this.botm_actions = false
						}
						
					}
					
					if(_this.setData.work_show_type==1 && !_this.workDataIsNoMore){
						let windowHeight = uni.getSystemInfoSync().windowHeight
						let domToTop =  _this.$refs.actionMore.getBoundingClientRect().top
						if(windowHeight>domToTop && !_this.sock){
							_this.getMoreWorks()
						}
					}
				}
			},
			//被当做iframe引用时处理数据
			setIframeData(){
				let _this = this
				window.addEventListener('message',function(e){
					console.log('iframe接收到的数据',e.data)
					let data = e.data
					_this.actid = data.slug
					// return
					//强制兼容后台数据
					_this.frameData={ code:0, data:data }
					let {settings}=data
					_this.activityText={
						view_num:settings.view_num,
						play_num:settings.play_num,
						win_num:settings.win_num,
					}
					_this.groupData =[
						{name:'全部',id:''},
						{id: 36, actid: 771, sort: 1, name: "分组1", num: 0, status: 1, created_at: 1698909127},
						{id: 37, actid: 771, sort: 1, name: "分组2", num: 0, status: 1, created_at: 1698909131}
					]
					_this.worksData=[
						{
							attaches: [{url: require('@/static/vote/lott_prize.png')}, ],
							cover:[{thumb_url:require('@/static/vote/lott_prize.png')},],
							id: 33,
							name: "测试数据1",
							number: 112,
							speak: "我是宣言！",
							stats: {view_num: 207, first_num: 0, last_num: 445800},
							first_num: 0,
							last_num: 445800,
							view_num: 207,
							url: "",
							user_id: 5,
							sortNum:'001',
						},
						{
							attaches: [{url: require('@/static/vote/lott_prize.png')}, ],
							cover:[{thumb_url:require('@/static/vote/lott_prize.png')},],
							id: 33,
							name: "张三",
							number: 112,
							speak: "我肯定会勇夺第一！",
							stats: {view_num: 8501, first_num: 0, last_num: 445800},
							first_num: 0,
							last_num: 445800,
							view_num: 8501,
							url: "",
							user_id: 5,
							sortNum:'002',
						},
						{
							attaches: [{url: require('@/static/vote/lott_prize.png')}, ],
							cover:[{thumb_url:require('@/static/vote/lott_prize.png')},],
							id: 33,
							name: "李四",
							number: 112,
							speak: "我肯定会勇夺第一！",
							stats: {view_num: 8501, first_num: 0, last_num: 445800},
							first_num: 0,
							last_num: 445800,
							view_num: 8501,
							url: "",
							user_id: 5,
							sortNum:'002',
						}
					]
					_this.workDataIsNoMore = true
					let {popup} = data
					switch(popup){
						case 'win_popup':
							_this.serviceData = { id: 116, redid: 0, title: "示例奖品", type: 2, }
							_this.serviceData.win_popup = _this.setData.win_popup
							_this.modalData.show=true
							_this.modalData.type=2
							break;
						case 'closewin_popup':
							_this.modalData.show=false
							break;
						case "task_popup":
							_this.taskMenuData = frameJs.taskMenuData
							_this.showTask=true
							break;
						case "closetask_popup":
							_this.showTask=false
							break;
						default:break;
					}
					_this.init()
				})
			},
			initCapt(){
				let _this = this
				let captchaId = captID; //腾讯滑块验证码appid
				        //生成一个滑块验证码对象
				this.captcha = new TencentCaptcha(captchaId, function (res) {
				    if (res.ret === 0) {
						_this.captData = res
				            // 页面上滑动正确，请求自己的业务接口
				            // 记得把验证成功的票据和随机字符带到自己接口中去腾讯验证票据的真实性
				         _this.voteModal = true   
				    }
				});
			},
		},
		async mounted() {
			this.loginStatus = await checkLogin()
			if(!this.isframe){
				this.initCapt()
				this.init()
				this.getActivity()
				this.initGroup()
			
			}else{
				this.setIframeData()
			}
			
		},
		created() {
			this.actid =uni.getStorageSync('actid')
			this.$store.commit('SETACTIVITYNAME','vote')
			let web  = uni.getStorageSync('WEB') || null
			// console.log('created',web)
			if(web){
				this.isframe = true
			}
			let code = uni.getStorageSync(this.actid+'Invite') || 0
			if(code != 0 ){
				this.showHelpModal = true
			}
		},
		destroyed() {
			window.onscroll = ()=>{}
		}
	}
</script>

<style lang="scss" scoped>
	@import "./vote.scss";
	@import "../vote/lott.scss"
</style>